<template>
  <div>
    <div class="topheader">
      <div class="img">
        <img :src="playlist.coverImgUrl" alt="">
      </div>
      <div class="button" @click="$router.go(-1)">
          <span class="iconfont icon-arrow-left-bold"></span>
          歌单
      </div>
      <div class="title">
         {{playlist.name}}
      </div>
    </div>

    <div class="musiclist">
        <ul>
          <li>
            <div class="left-list iconfont icon-bo413"></div>
            <div class="right-list">
              <p class="song">播放全部<span>(共{{playlist.tracks.length}}首)</span></p>
            </div>
          </li>
          <li v-for="(item,index) in playlist.tracks" :key="index" @click="playmusic(item.id,item.name,item.ar)">
            <div class="left-list">{{index+1}}</div>
            <div class="right-list">
              <p class="song">{{item.name}}</p>
              <p class="singers">
                  <span v-for="(key,index) in item.ar" :key="index" >{{key.name}} &nbsp;&nbsp;</span>
              </p>
            </div>
          </li>
        </ul>
      </div>

      <!-- 评论 -->
      <div class="comment" v-if="comments.length">
        <div class="title">最新评论({{comments.length}})</div>
        <ul>
          <li v-for="(item,index) in comments" :key="index">
            <div class="left">
              <img :src="item.user.avatarUrl+'?param=50y50'" alt="">
            </div>
            <div class="right">
              <p class="name">{{item.user.nickname}}</p>
              <!-- <p class="time">{{item.time | playertime}}</p> -->
              <p class="text">{{item.content}}</p>
            </div>
          </li>
        </ul>
      </div>
  </div>
</template>

<script>
import {getDetail,getComment} from "../../api/recommend";
export default {
    data() {
        return {
            playlist:{
                tracks:[],
            },
            comments:[],
        }
    },
    methods:{
        getDetailFun(){
            let id = this.$route.query.id;
            if(!id){
                return ;
            }
            getDetail({id:id}).then(data=>{
                // console.log(data);
                this.playlist = data.playlist;
            })
        },
        playmusic(id,name,ar){
          let playMusicData = {
            coverImgUrl:this.playlist.coverImgUrl,
            id,
            name,
            ar,
            tracks:this.playlist.tracks
          }
          // 数据存储
          this.$store.commit("musicDatafun",playMusicData )

        },
        getCommentFun(){
          let id = this.$route.query.id;
          getComment({id:id}).then(data=>{
            // console.log(data.comments)
            this.comments = data.comments
          })
        }
    },
    created(){
        this.getDetailFun();
    },
    mounted(){
        this. getCommentFun();
    }
}
</script>


<style lang="less">
.comment{
  .title{
    font-size: 18px;
    margin-left: 10px;
  }
  ul{
    li{
      overflow: hidden;
      background: #fff;
      padding: 10px;
      border-bottom: 1px solid #ccc;
      .left{
        float: left;
        width: 30px;
        height: 30px;
        border-radius: 50%;
        overflow: hidden;
        // background: pink;
        margin-right: 10px;
        img{
          width: 100%;
        }
      }
      .right{
        float: left;
        width: 300px;
        p{
          margin: 0px;
          &.name{
            font-size: 14px;
            color: #666;
          }
          &.time{
            font-size: 12px;
            color: #999;
          }
          &.text{
            font-size: 16px;
            color: #333;
            margin-top: 5px;
          }
        }
      }
    }
  }
}



body {
  background: #F2F2F2;
}
.topheader {
  position: relative;
  .img {
    height: 300px;
    // background: pink;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .button {
    position: absolute;
    top: 12px;
    left: 12px;
    font-size: 16px;
    color: #fff;
  }
  .title{
    position: absolute;
    left:12px;
    right: 12px;
    bottom: 30px;
    font-size: 16px;
    font-weight: bold;
    color:#fff;
    height: 38px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.musiclist ul li:first-of-type {
    height: 35px;
    line-height: 35px;
    padding: 0px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    background: #f2f3f4;
    span{
        font-size: 12px;
    }
    .iconfont{
        line-height: 35px;
        font-size: 20px;
    }
  }
  .musiclist ul {

      // margin-top: -35px;
      position: relative;
      top: -35px;
    li {
      height: 30px;
      // line-height: 52px;
      margin-bottom: 4px;
      background: #fff;
      color: #333;
      padding: 11px 0px;
      display: flex;
      .left-list {
        width: 44px;
        height: 32px;
        line-height: 32px;
        text-align: center;
        font-size: 14px;
      }
      .right-list {
        width: 200px;
        p{
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          margin: 0px;
          &.song {
            font-size: 16px;
          }
          &.singers {
            font-size: 12px;
            line-height: 22px;
          }
        }
      }
    }
  }
</style>
